<?php

/**
 * SocialEngine
 *
 * @category   Application_Extensions
 * @package    Sitealbum
 * @copyright  Copyright 2010-2011 BigStep Technologies Pvt. Ltd.
 * @license    http://www.socialengineaddons.com/license/
 * @version    $Id: index.tpl 2011-08-026 9:40:21Z SocialEngineAddOns $
 * @author     SocialEngineAddOns
 */
?>
<?php 
	$baseUrl = $this->seaddonsBaseUrl();
	$this->headLink()
  ->appendStylesheet($this->seaddonsBaseUrl()
    . '/application/modules/Sitealbum/externals/styles/style_sitealbum.css')
?>
<?php
if(empty($this->is_ajax)):
    if ($this->showLightBox):
    include_once APPLICATION_PATH . '/application/modules/Sitealbum/views/scripts/_lightboxPhoto.tpl';
  endif;
$this->headScript()
    ->appendFile($this->seaddonsBaseUrl() . '/application/modules/Sitealbum/externals/scripts/core.js')
    ->appendFile($this->seaddonsBaseUrl() . '/application/modules/Sitealbum/externals/scripts/album_comment.js');
?>

<?php if ($this->comment_view=="false") : ?>
	<?php if(!empty ($this->comment_enable)):?>
		<div class="sitealbum_buttons">
			<a href="<?php echo $this->subject()->getHref()?>" class="sitealbum_button_active">
				<div class="album_show_tooltip"><?php echo $this->translate('Album View') ?></div>
				<img src="application/modules/Sitealbum/externals/images/grid-icon.png" alt="Thumb" align="center" />
			</a>
			<a href="<?php echo $this->subject()->getHref()?>/comment/true">
				<div class="album_show_tooltip"><?php echo $this->translate('Comment View') ?></div>
				<img src="application/modules/Sitealbum/externals/images/list-icon.png" alt="List" align="center" />
			</a>
		</div>
	<?php endif ?>
<?php else: ?>
	<div class="sitealbum_buttons">
		<a href="<?php echo $this->subject()->getHref()?>">	
			<div class="album_show_tooltip"><?php echo $this->translate('Album View') ?></div>
			<img src="application/modules/Sitealbum/externals/images/grid-icon.png" alt="Thumb" align="center" />
		</a>
		<a href="<?php echo $this->subject()->getHref()?>/comment/true" class="sitealbum_button_active">
			<div class="album_show_tooltip"><?php echo $this->translate('Comment View') ?></div>
			<img src="application/modules/Sitealbum/externals/images/list-icon.png" alt="List" align="center" />
		</a>
	</div>
<?php endif ?>

<?php if($this->canComment):?>
	<div class="seaddons_like_button sitealbum_like_button">
		<a id="<?php echo $this->subject()->getType() ?>unlike_link" href="javascript:void(0);" onclick="en4.sitealbum.likes.unlike('<?php echo $this->subject()->getType() ?>', '<?php echo $this->subject()->getIdentity() ?>');"  <?php if (!$this->subject()->likes()->isLike($this->viewer())): ?> style="display: none;" <?php endif; ?> >	<i class="seaddons_like_thumbdown_icon"></i>
			<span><?php echo $this->translate('Unlike') ?></span>
		</a>
		<a id="<?php echo $this->subject()->getType() ?>like_link" href="javascript:void(0);" onclick="en4.sitealbum.likes.like('<?php echo $this->subject()->getType() ?>', '<?php echo $this->subject()->getIdentity() ?>');"  <?php if ($this->subject()->likes()->isLike($this->viewer())): ?> style="display: none;" <?php endif; ?>  >	<i class="seaddons_like_thumbup_icon"></i>
			<span><?php echo $this->translate('Like') ?></span>
		</a>
	</div>
<?php endif; ?>

<h2>
  <?php echo $this->translate('%1$s\'s Album: %2$s',
    $this->album->getOwner()->__toString(),
    ( '' != trim($this->album->getTitle()) ? $this->album->getTitle() : '<em>' . $this->translate('Untitled') . '</em>')
  ); ?>
</h2>
<?php if( '' != trim($this->album->getDescription()) ): ?>
  <p>
    <?php echo $this->album->getDescription() ?>
  </p>
  <br />
<?php endif ?>

<!--FACEBOOK LIKE BUTTON START HERE-->
  <?php $fbmodule = Engine_Api::_()->getDbtable('modules', 'core')->getModule('facebookse');
  if (!empty ($fbmodule)) :
    $enable_facebookse = Engine_Api::_()->getDbtable('modules', 'core')->isModuleEnabled('facebookse'); 
    if (!empty ($enable_facebookse) && !empty ($fbmodule->version)) :
      $fbversion = $fbmodule->version; 
      if (!empty($fbversion) && ($fbversion >= '4.1.7')) { ?>
      
        <div>
          <?php echo Engine_Api::_()->facebookse()->isValidFbLike('album') . '<br />' ; ?>
        </div>
        
      <?php } ?>
    <?php endif; ?>
  <?php endif; ?>

<?php if( $this->mine || $this->canEdit || $this->canMakeFeatured || $this->isSugg ): ?>
  <div class="sitealbum_album_options">
   <?php if( $this->canMakeFeatured && !$this->allowView ): ?>
    <div class="tip">
      <span>
        <?php echo $this->translate("SITEALBUM_VIEW_PRIVACY_MESSAGE");?>
      </span>
    </div>
   <?php endif; ?>
	<?php
		if( !empty($this->isSugg) ):
			echo $this->htmlLink(array('route' => 'default', 'module' => 'suggestion', 'controller' => 'index', 'action' => 'switch-popup', 'modName' => 'album', 'modContentId' => $this->album->album_id), $this->translate('Suggest to Friends'), array( 'class'=>'buttonlink  icon_page_friend_suggestion smoothbox'));
		endif; ?>
    <?php if( $this->mine || $this->canEdit  ): ?>
    <?php echo $this->htmlLink(array('route' => 'album_general', 'action' => 'upload', 'album_id' => $this->album->album_id), $this->translate('Add More Photos'), array(
      'class' => 'buttonlink icon_photos_new'
    )) ?>
     <?php if(!empty($this->count)): ?>
      <?php echo $this->htmlLink(array('route' => 'album_specific', 'action' => 'editphotos', 'album_id' => $this->album->album_id), $this->translate('Manage Photos'), array(
        'class' => 'buttonlink icon_photos_manage'
      )) ?>
      <?php endif; ?>
    <?php echo $this->htmlLink(array('route' => 'album_specific', 'action' => 'edit', 'album_id' => $this->album->album_id), $this->translate('Edit Settings'), array(
      'class' => 'buttonlink icon_photos_settings'
    )) ?>
    <?php echo $this->htmlLink(array('route' => 'album_specific', 'action' => 'delete', 'album_id' => $this->album->album_id, 'format' => 'smoothbox'), $this->translate('Delete Album'), array(
      'class' => 'buttonlink smoothbox icon_photos_delete'
    )) ?>
      <?php if(Engine_Api::_()->getApi('settings', 'core')->getSetting('sitealbum.photo.badge', 1)):?>
     <?php echo $this->htmlLink(array('route' => 'sitealbum_badge', 'action' => 'create', 'album_id' => $this->album->album_id), $this->translate('Share via Badge'), array(
      'class' => 'buttonlink sitealbum_icon_badge_create'
    )) ?>
    <?php endif;?>
   <?php endif;?>
    <?php if( $this->canMakeFeatured && $this->allowView ): ?>    
    <a href="javascript:void(0);" class="buttonlink seaddons_icon_featured" onclick='featured();' ><span id="featured_sitealbum" <?php if($this->subject()->featured): ?> style="display:none;" <?php endif;?> title="<?php echo $this->translate("Make Featured"); ?>" ><?php echo $this->translate("Make Featured"); ?> </span> <span id="un_featured_sitealbum" <?php if(!$this->subject()->featured): ?> style="display:none;" <?php endif;?> title="<?php echo $this->translate("Make Un-Featured"); ?>" > <?php echo $this->translate("Make Un-featured"); ?> </span></a>
   <?php echo $this->htmlLink(array('route' => 'sitealbum_extended', 'controller'=>'album','action' => 'add-album-of-day', 'album_id' => $this->album->album_id, 'format' => 'smoothbox'), $this->translate('Make Album of the Day'), array(
      'class' => 'buttonlink smoothbox item_icon_album'
    )) ?>
    <?php endif;?>
  </div>
<?php endif;?>

<?php endif; ?>
<?php if ($this->comment_view=="false") : ?>
<?php if (empty($this->is_ajax)) : ?>
<?php if( $this->mine || $this->canEdit ): ?>
  <script type="text/javascript">
    function SortablesInstance(){
    var SortablesInstance;
      $$('.thumbs_nocaptions > li').addClass('sortable');
      SortablesInstance = new Sortables($$('.thumbs_nocaptions'), {
        clone: true,
        constrain: true,
        //handle: 'span',
        onComplete: function(e) {
          var ids = [];
          $$('.thumbs_nocaptions > li').each(function(el) {
            ids.push(el.get('id').match(/\d+/)[0]);
          });
          //console.log(ids);

          // Send request
          var url = '<?php echo $this->url(array('action' => 'order'),'album_specific') ?>';
          var request = new Request.JSON({
            'url' : url,
            'data' : {
              format : 'json',
              order : ids
            }
          });
          request.send();
        }
      });
  }
  </script>
<?php endif ?>
<script type="text/javascript">
  function viewMorePhoto()
  {
    $('view_more').style.display ='none';
    $('loding_image').style.display ='';
    en4.core.request.send(new Request.HTML({
      method : 'post',
      'url' : en4.core.baseUrl + 'widget/index/mod/sitealbum/name/album-view',
      'data' : {
        format : 'html',
        'subject' : '<?php echo $this->subject()->getGuid() ?>',
        isajax : 1,
        itemCountPerPage : '<?php echo $this->itemCountPerPage ?>',
        margin_photo : '<?php echo $this->marginPhoto ?>',
        page: getNextPage()
      },
      onSuccess : function(responseTree, responseElements, responseHTML, responseJavaScript) {    
        $('hideResponse_div').innerHTML=responseHTML;      
        var photocontainer = $('hideResponse_div').getElement('.layout_sitealbum_album_view').innerHTML;
        $('photos_layout').innerHTML = $('photos_layout').innerHTML + photocontainer;
        $('loding_image').style.display ='none';
        $('hideResponse_div').innerHTML="";
        <?php if( $this->mine || $this->canEdit ): ?>
            SortablesInstance();
        <?php endif; ?>
      }
    }));

    return false;

  }  
</script>
	<div class="sitealbum_album_photos sitealbum_grid_view">
	  <ul class="thumbs thumbs_nocaptions" id="photos_layout">
	    <?php endif ?>
	    <?php foreach( $this->paginator as $photo ): ?>
	      <li id="thumbs-photo-<?php echo $photo->photo_id ?>" style="margin-left:<?php echo $this->marginPhoto ?>px;margin-right:<?php echo $this->marginPhoto ?>px;">     
	        <a class="thumbs_photo" href="<?php echo $photo->getHref(); ?>" <?php if($this->showLightBox): ?>onclick='openLightBoxAlbum("<?php echo $photo->getPhotoUrl()?>","<?php echo Engine_Api::_()->sitealbum()->getLightBoxPhotoHref($photo); ?>");return false;' <?php endif; ?>>
	          <span style="background-image: url(<?php echo $photo->getPhotoUrl('thumb.normal'); ?>);"></span>
	        </a>       
	      </li>     
	    <?php endforeach;?>
	  <?php if (empty($this->is_ajax)) : ?>
	    <?php
	     if(empty($this->count)):?>
	      <li>
	        <div class="tip">
	          <span>
	            <?php echo $this->translate('There are no photos in this album.')?>
	          </span>
	        </div>
	      </li>
	    <?php endif; ?>
	  </ul>
	  <br />
		<div class="sitealbum-album-more" id="view_more" onclick="viewMorePhoto()">
	  <?php echo $this->htmlLink('javascript:void(0);', $this->translate('View More'), array(
	    'id' => 'feed_viewmore_link',
	    'class' => 'buttonlink icon_viewmore'
	  )) ?>
	  </div>
		<div class="sitealbum-album-more" id="loding_image" style="display: none;">
		  <img src='application/modules/Core/externals/images/loading.gif' style='margin-right: 5px;' />
		  <?php echo $this->translate("Loading ...") ?>
		</div>
	</div>
	<div id="hideResponse_div" style="display: none;"></div>
 <?php endif; ?>

<script type="text/javascript">
    en4.core.runonce.add(function() {
    hideViewMoreLink();
    <?php if( $this->mine || $this->canEdit ): ?>
    SortablesInstance();
    <?php endif; ?>
  });
    function getNextPage(){
      return <?php echo sprintf('%d', $this->paginator->getCurrentPageNumber() + 1) ?>
    }
    function hideViewMoreLink(){
        $('view_more').style.display = '<?php echo ( $this->paginator->count() == $this->paginator->getCurrentPageNumber() || $this->count == 0 ? 'none' : '' ) ?>';
    }
</script>
 <!-- // Commented View -->
<?php else: ?>
	<div class="sitealbum_comment_view sitealbum_album_photos">
	   <ul class="thumbs" id="photos_layout">   
	    <?php foreach( $this->paginator as $photo ): ?>
	      <li id="thumbs-photo-<?php echo $photo->photo_id ?>">
	        <a class="thumbs_photo" href="<?php echo $photo->getHref(); ?>" <?php if($this->showLightBox): ?>onclick='openLightBoxAlbum("<?php echo $photo->getPhotoUrl()?>","<?php echo Engine_Api::_()->sitealbum()->getLightBoxPhotoHref($photo); ?>");return false;' <?php endif; ?>>
	          <img src="<?php echo $photo->getPhotoUrl(); ?>" alt="" align="center" />
	        </a> 
	             
	        <div class="sitealbum_comment_view_comments">
	          <?php if (!empty($photo->description) ): ?>
	           <div class="photo_des">
	            <?php echo $photo->getDescription() ?>
	          </div>    
	          <?php endif; ?>
	            <?php echo $this->action("list", "comment", "sitealbum", array("type"=>$photo->getType(), "id"=>$photo->getIdentity())); ?>
	        </div>
	      </li>
	    <?php endforeach;?>
	      <?php echo $this->paginationControl($this->paginator); ?>
	   <?php 
	     if(empty($this->count)):?>
	      <li>
	        <div class="tip">
	          <span>
	            <?php echo $this->translate('There are no photos with comments in this album.')?>
	          </span>
	        </div>
	      </li>
	    <?php endif; ?>
	  </ul>
	</div>
<?php endif; ?>
<?php if (empty($this->is_ajax)) : ?>
<br />
 <?php echo $this->action("list", "comment", "core", array("type"=>"album", "id"=>$this->album->getIdentity())); ?>
<?php endif; ?>
 <script type="text/javascript">
  function featured()
  { 
    en4.core.request.send(new Request.HTML({
      method : 'post',
      'url' : en4.core.baseUrl + 'sitealbum/album/featured',
      'data' : {
        format : 'html',
        'subject' : '<?php echo $this->subject()->getGuid() ?>'
      },
      onSuccess : function(responseTree, responseElements, responseHTML, responseJavaScript) {       
       if($('featured_sitealbum').style.display=='none'){
        $('featured_sitealbum').style.display="";
        $('un_featured_sitealbum').style.display="none";
       }else{
          $('un_featured_sitealbum').style.display="";
        $('featured_sitealbum').style.display="none";
       }
      }
    }));

    return false;

  }
</script>